package com.cg.Validation;

import com.cg.anno.State;
import jakarta.validation.ConstraintValidator;
import jakarta.validation.ConstraintValidatorContext;

public class StateValidation implements ConstraintValidator</*给哪个注解提供校验规则*/State,/*校验的数据类型*/String> {

    /**
     *
     * @param value 将来要校验的数据
     * @param context context in which the constraint is evaluated
     *
     * @return 如果返回false，则校验不通过，如果返回true，则返回通过
     */
    @Override
    public boolean isValid(String value, ConstraintValidatorContext context){
        //提供校验规则
        if(value==null){
            return false;
        }

        if(value.equals("已发布")||value.equals("草稿")){
            return true;
        }
        return false;

    }
}
